#include <stdio.h>
#include "vc.h"



int main(int argc,  char **argv)
{
  int N = 0;
  /* Read in the power of 2 from command line */
  if (argc >= 2)
    N = pow(2, atoi(argv[1]) );
  else 
    N = pow(2,16);

  // number of iterations for relaxtion going down and up
  int nu_up   = 500;
  int nu_down = 200;

  int flag = 0;
  int i;

  int nts;
  double error;

  double *v_in = (double *)malloc((N+1) * sizeof(double));
  double *v_out= (double *)malloc((N+1) * sizeof(double));
  double *f_in = (double *)malloc((N+1) * sizeof(double));

  double t0, t1, dt;

  srand(100);

  for(i = 0; i < N+1; i++)
    {
      f_in[i] = 0;                        //f_in is fixed at 0
      v_in[i] = rand()/ (RAND_MAX+1.0);   //v_in is randomly generated between 0 and 1
    }

  // Vcycle_1d function
  t0 = omp_get_wtime();
  flag = Vcycle_1d(v_in, f_in, N+1, nu_down, nu_up, v_out);
  t1 = omp_get_wtime();
  dt = t1 - t0;

  // Post processing
#pragma omp parallel
  nts = omp_get_num_threads();

  error = get_2norm_error(v_out, N+1);
  printf("%6i %10.6f %10.6fs\t \n", nts, error, dt);


  free(v_in);
  free(v_out);
  free(f_in);

  return 0;
}
